<%--
  Created by IntelliJ IDEA.
  User: LT
  Date: 2018-10-25
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/statics/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/statics/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/statics/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>
        function searcha() {
            //返回表格的 Options。
            var opts = $("#fuwuxiangmu").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var username = $("#username").val() ;
            $.post("${pageContext.request.contextPath}/shangpin/queryByName",{'name':username,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#fuwuxiangmu").bootstrapTable('load',data) ;
            })
        }

        $(function () {
            $("#fuwuxiangmu").bootstrapTable({
                url:'${pageContext.request.contextPath}/shangpin/queryByName',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:380,
                pageNumber:1,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        username:$("#username").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        field:'quchushijian',
                        title:'取出时间'
                    },
                    {
                        field:'huiyuan_Id',
                        title:'会员编号'
                    },
                    {
                        field:'huiyuan_Name',
                        title:'会员姓名'
                    },
                    {
                        field:'shangpin_Name',
                        title:'商品名称'
                    },
                    {
                        field:'danwei',
                        title:'商品单位'
                    },
                    {
                        field:'quchushuliang',
                        title:'取出数量'
                    },
                    {
                        field:'weiqu_Shuliang',
                        title:'剩余数量'
                    },
                    {
                        field:'jicun_Danhao',
                        title:'单号'
                    },
                    {
                        field:'dianpu_Name',
                        title:'操作店铺'
                    },
                    {
                        field:'beizhu',
                        title:'备注信息'
                    }],
            }) ;
        }) ;


        function tofenpei(id){
            userinfoid = id ;
            userinfoid = id ;
            var a = 0 ;
            var s = "" ;
            // <div class="radio-inline">
            //<input type='radio' value=>
            //  <label>管理员</label>
            //</div>
            //打开一个对话框
            $("#fenpei").modal('show') ;
            //当对话框加载完成后，绑定年有角色
            $("#fenpei").on("shown.bs.modal",function(){
                //
                if (++a ==1){
                    $.post('${pageContext.request.contextPath}/role/query',{"id":id},function(data){
                        for (var i=0;i<data.length;i++){
                            var r = data[i] ;
                            var id = r.id ;
                            var rname = r.rname ;
                            var ischecked = r.ischecked ;
                            if (ischecked) {
                                s = s + "<div class='radio-inline'><input  name='js' checked type='radio' value=" + id + "></input><label>" + rname + "</label></div>";
                            }
                            else
                            {
                                s = s + "<div class='radio-inline'><input  name='js'  type='radio' value=" + id + "></input><label>" + rname + "</label></div>";
                            }
                        }
                        $("#juesebody").html(s) ;
                    }) ;
                }

            }) ;

        }

        function toadd() {
            $("#modelId").modal("show") ;
        }

        var userinfoid ;

        function dofenpei() {
            //1.得到用户的id，角色的id
            var roleid = $("input[name='js']:checked").val() ;
            //2.send ajax
            $.post("${pageContext.request.contextPath}/user/doFenPei",{'userinfoid':userinfoid,'roleid':roleid},function(){
                //关闭对话框,刷新表格
                $("#fenpei").modal('hide') ;
                //   $("#usertb").bootstrapTable('load') ;
            }) ;
        }
    </script>

</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">商品取出记录</h3>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-6">
                <button onclick="toadd()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;增加</button>
            </div>
            <div class="col-sm-6">
                <form  class="form-inline pull-right">
                    <input id="username" type="text" class="form-control">
                    <button class="btn btn-primary" onclick="searcha()" type="button"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;搜索</button>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="fuwuxiangmu"></table>
            </div>
        </div>

    </div>
</div>

</body>
</html>
